package 科大讯飞;

import java.util.*;

public class Q3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        List<Integer> k = new ArrayList<>();
        for(int i = 0; i< T;i++){
            k.add(scanner.nextInt());
        }
        for (int t = 0; t < T; t++) {
            int n = k.get(t);
            List<Integer> factors = new ArrayList<>();

            // 生成所有可能的 2^a * 3^b
            for (int i = 1; i <= n; i *= 2) {
                for (int j = i; j <= n; j *= 3) {
                    if (j <= n) {
                        factors.add(j);
                    }
                }
            }

            // 排序因子列表
            Collections.sort(factors);

            // 用于存储结果的列表
            List<Integer> result = new ArrayList<>();
            // 递归找到所有组合
            findCombination(n, factors, result);

            System.out.println(result.size());
            // 输出结果
            for (int num : result) {
                System.out.print(num + " ");
            }
            System.out.println();
        }
    }

    private static void findCombination(int target, List<Integer> factors, List<Integer> result) {
        if (target == 0) {
            return;
        }

        for (int i = factors.size() - 1; i >= 0; i--) {
            if (factors.get(i) <= target) {
                result.add(factors.get(i));
                findCombination(target - factors.get(i), factors, result);
                return; // 这里应为return，而不是break，确保每次递归选择合适的因子组合
            }
        }
    }
}
